package com.qdsgjsfk.vision.ui;

import android.content.Context;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RelativeLayout;

import com.qdsgjsfk.vision.R;

import butterknife.BindView;
import butterknife.OnClick;

import com.qdsgjsfk.vision.base.BaseActivity;
import com.qdsgjsfk.vision.ui.fragment.CollectClassFragment;

/**
 * 人脸采集，选择班级
 * Created by lbj on 2021/9/6 14:33
 */

public class CollectClassActivity extends BaseActivity {

    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;

    @BindView(R.id.title)
    RelativeLayout title;
    private String taskId;


    @Override
    protected void initViews() {
        mViewPager.setAdapter( new ClassListAdapter( this, getSupportFragmentManager() ) );
        mTabLayout.setupWithViewPager( mViewPager );
        mTabLayout.setTabMode( TabLayout.MODE_FIXED );
        mTabLayout.setTabGravity( TabLayout.GRAVITY_FILL );

        mViewPager.setCurrentItem( 0 );
        mTabLayout.getTabAt( 0 ).select();
        title.bringToFront();
    }

    @Override
    protected void initData() {
        taskId = getIntent().getStringExtra( "taskId" );
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_collect_class_list;
    }


    class ClassListAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 3;

        private Context mContext;

        public ClassListAdapter(Context context, FragmentManager fm) {
            super( fm );
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            String type;
            switch (position) {
                case 0:
                    type = "";
                    break;
                case 1:
                    type = "0";
                    break;
                case 2:
                    type = "1";
                    break;
                default:
                    type = "";
                    break;
            }
            return CollectClassFragment.newInstance( type, taskId );
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "全部";
                case 1:
                    return "未采集完";
                case 2:
                    return "采集完";
                default:
                    return "";
            }
        }

    }

    @OnClick(R.id.btn_search)
    void btn_search() {
        startActivity( CollectSearchStudentActivity.class );
    }

}
